using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Visitors;

namespace ModelGenerator.ModelGenerator
{
    public class ClassVisitor : AbstractAstVisitor
    {
        private readonly string filePath;
        private readonly string targetDirectory;
        private readonly string targetNamespace;

        /// <summary>
        /// Initializes a new instance of the <see cref="ClassVisitor"/> class.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="targetDirectory">The target directory.</param>
        /// <param name="targetNamespace">The target namespace.</param>
        public ClassVisitor(string filePath, string targetDirectory, string targetNamespace)
        {
            this.filePath = filePath;
            this.targetNamespace = targetNamespace;
            this.targetDirectory = targetDirectory;
        }

        /// <summary>
        /// Visits the type declaration.
        /// </summary>
        /// <param name="typeDeclaration">The type declaration.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            // -1 to copy the class attribute
            int startlocation = typeDeclaration.StartLocation.Y - 1;
            int endlocation = typeDeclaration.EndLocation.Y;
            FileMover.moveCode(startlocation, endlocation, filePath, typeDeclaration.Name, targetDirectory,
                               targetNamespace);
            return null;
        }
    }
}